open(BUFF,"final.tfam") or die " no tfam file found\n";
$num = 0;
#selecting sampes from tfam with only tumor (creating hash}
while(<BUFF>)
{
	chomp($_);
	@a = split(" ",$_);
	@b = split('-',$a[0]);
	#$num++;
	if($b[3] =~ m/^10/)
	{
		$sample{$num} = $a[1];
	}
	$num++;	
}
open(BUFF,"final.dosage") or die " no dosage file found\n";
open(WRBUFF,">SNP1.txt") or die "not able to write\n";
#writing header
$header = "rsid";
for($i=0;$i<$num;$i++)
{
	if(exists($sample{$i}))
	{
		$header =$header."\t".$sample{$i};
	}
}
print WRBUFF $header."\n";
while(<BUFF>)
{
        chomp($_);
	@a = split(" ",$_);
	$rsid = shift(@a);
	print WRBUFF $rsid.
	shift(@a);
	shift(@a);
	for($i=0;$i<@a/2;$i++)
	{
		$gnt1 = $a[2*$i];
		$gnt2 = $a[2*$i+1];
		$dos = 2*($gnt1)+$gnt2;
        	if(exists($sample{$i}))
        	{
                	print WRBUFF "\t$dos";
        	}
	}
	print WRBUFF "\n";
		
}
if(@a/2 != $num)
{
	die "samples in dosage not equal to tfam samples\n";
}
